package org.example.myleet.rosalind.mmch;

import org.example.myleet.rosalind.utils.BigNumberOperator;
import org.example.myleet.rosalind.utils.FastaReader;

import java.math.BigInteger;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
//        solution.calculateCombinations(FastaReader.parseFastaInput(">Rosalind_92\n" +
//                "AUGCUUC\n").get(0).getSequence());
//        solution.calculateCombinations(FastaReader.parseFastaInput(">Rosalind_1280\n" +
//                "AGCUCAACCAAGGGCCAAGUUAGUGCUGGAUGCUGCACAUUGGUAGGCGAUAUGACACAC\n" +
//                "UAUGGCACAAACCUGUUCCG\n").get(0).getSequence());
        solution.calculateCombinations(FastaReader.parseFastaInput(">Rosalind_2255\n" +
                "CUGGUGACUGUAGGUACUCUGAAGUUUGAGUUCCCAAUCAAACAGAGCGCUUGGGAAUCU\n" +
                "AUAGCGCAACCCUUUCGGGCGUAAUUCUGGAUGG\n").get(0).getSequence());
    }

    public void calculateCombinations(String sequence) {
        int a = 0, c = 0, g = 0, u = 0;
        char ch;
        for (int i = 0; i < sequence.length(); ++i) {
            ch = sequence.charAt(i);
            switch (ch) {
                case 'A': {
                    ++a;
                    break;
                }
                case 'C': {
                    ++c;
                    break;
                }
                case 'G': {
                    ++g;
                    break;
                }
                case 'U': {
                    ++u;
                    break;
                }
                default:
                    throw new RuntimeException("Not valid RNA!");
            }
        }
        BigInteger res = permutation(a, u);
        res = res.multiply(permutation(c, g));
        System.out.println(res);
    }

    private BigInteger permutation(int a, int b) {
        if (a < b) {
            return permutation(b, a);
        }
        return BigNumberOperator.permutation(a, b);
    }
}
